import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author: Lenovo
 * @Date: 2024/6/10 11:17
 * @description:
 */
public class CardDemo {
    public static final String[]suits={"♣","♦","♥","♠"};
    public List<Card> buyCard(){
        List<Card>cards=new ArrayList<>(52);
        for (int i=0;i<4;i++){
            for (int j=1;j<=13;j++){
                int rank=j;
                String suit=suits[i];
                Card card=new Card(rank,suit);
                cards.add(card);
            }
        }
        return cards;
    }
    private void Swap(List<Card>cards,int i,int j){
            Card tmp=cards.get(i);
            cards.set(i,cards.get(j));
            cards.set(j,tmp);
    }
    //洗牌
    public void shuttle(List<Card>cards){
        Random random=new Random();
        for (int i = cards.size()-1; i >0 ; i--) {
            int index=random.nextInt(i);
            Swap(cards,i,index);
        }
    }
    //发牌
    public List<List<Card>> play(List<Card>cards){
        List<List<Card>>hand=new ArrayList<>(3);
        List<Card>hand1=new ArrayList<>();
        List<Card>hand2=new ArrayList<>();
        List<Card>hand3=new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i=0;i<5;i++){
            for (int j=0;j<3;j++){
                Card card=cards.remove(0);
                hand.get(j).add(card);
            }
        }
        return hand;
    }
}
